﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.Dependency;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Abp.RemoteEventBus;
using Abp.Runtime.Caching;
using FwProject.Core.Distribution;
using FwProject.Core.Restaurant;
using FwProject.Distribution;
using FwProject.Distribution.Dto;
using FwProject.Restaurant;
using FwProject.Users;
using Microsoft.EntityFrameworkCore;

namespace FwProject.RemoteEventBus
{

    [Obsolete("已经过期")]
    // [RemoteEventHandler(ForType = "Update", ForTopic = "SystemDistributionInfoStatus")]
    public class UpdateDistributionStauts : IRemoteEventHandler, ITransientDependency
    {

        IRepository<DistributionInfo, Guid> _repositoryDistributionInfo;

        public UpdateDistributionStauts(IRepository<DistributionInfo, Guid> repositoryDistributionInfo)
        {
            _repositoryDistributionInfo = repositoryDistributionInfo;

        }
        [UnitOfWork]
        public void HandleEvent(RemoteEventArgs eventArgs)
        {
            var t = _repositoryDistributionInfo.GetAll().Where(o => o.Pricestatus == Pricestatus.已配送 && o.CreationTime > DateTime.Now.AddHours(24));
            foreach (var item in t)
            {
                item.Pricestatus = Pricestatus.未结账;
            }

        }
    }

}
